
****** This program generates the results in Table A9 of the paper: heterogenous effects by type of i-j link *********


clear all
set more off, permanently
cd "$localdir\Data"
global output "$localdir\Output"


******** Interaction with type of i-j link **************
* Note: the RF is at the i-k level, hence look at an indicator for at least one j of the particular network type (family, partner, work, study)

use "i-j-k links for RF", clear

* Check number of j's linking i to k each year
bysort year unique unique_k: gen count=_n
bysort year unique unique_k: egen maxcount=max(count)
sum maxcount if count==1, de

* Share of j's from each type of network
* Put together partner and family
egen temp=rowmax(partner family)
bysort year unique unique_k: egen dummy_family=max(temp)
bysort year unique unique_k: egen dummy_educ=max(educ)
bysort year unique unique_k: egen dummy_coworker=max(coworker)
drop temp

rename unique_k unique_network
keep year unique unique_network dummy_family dummy_educ dummy_coworker
duplicates drop year unique unique_network, force

save "i-j link type dummy", replace



***************************************************** ASSESSMENT OF NATIONAL UNEMPLOYMENT RATE ******************************************************

* Outcome only available in 2011 and 2012

use "National Unemployment RF for Analysis - Last Year.dta", clear

* Merge in unemployment rate estimate errors from last year 
merge 1:1 year unique unique_network using "i-j link type dummy"
keep if _merge==3
drop _merge

bysort unique year: egen grossunemp_enter_network_share=mean(grossunemp_enter_network)
bysort unique year: egen dummy_family_share=mean(dummy_family)
bysort unique year: egen dummy_educ_share=mean(dummy_educ)
bysort unique year: egen dummy_coworker_share=mean(dummy_coworker)
drop *_network dummy_family dummy_educ dummy_coworker
duplicates drop unique year, force

* Interactions
g unemp_family=grossunemp_enter_network_share*dummy_family_share
g unemp_educ=grossunemp_enter_network_share*dummy_educ_share
g unemp_coworker=grossunemp_enter_network_share*dummy_coworker_share

tab year 

lab var grossunemp_enter_network_share "Unemployment shock (network share)"
lab var dummy_family_share "Familial link (i-j share)"
lab var dummy_educ_share "Educational link (i-j share)"
lab var dummy_coworker_share "Vocational link (i-j share)"
lab var unemp_family "Unemployment shock x Familial link"
lab var unemp_educ "Unemployment shock x Educational link"
lab var unemp_coworker "Unemployment shock x Vocational link"
global link_vars "dummy_family_share dummy_educ_share dummy_coworker_share unemp_family unemp_educ unemp_coworker"

replace unemp_rate_estimate=unemp_rate_estimate/100

* Results
display c(current_time)
reghdfe unemp_rate_estimate grossunemp_enter_network_share $link_vars, absorb(both ind2_year ocp_year educ_year) cluster(muni)
sum unemp_rate_estimate if e(sample)==1
local mean_outcome=r(mean)
local sd_outcome=r(sd)
sum grossunemp_enter_network_share if e(sample)==1
local mean_shock=r(mean)
local sd_shock=r(sd)
sum dummy_family_share if e(sample)==1
local mean_fam=r(mean)
sum dummy_educ_share if e(sample)==1
local mean_educ=r(mean)
sum dummy_coworker_share if e(sample)==1
local mean_voc=r(mean)

test (grossunemp_enter_network + unemp_family)=(grossunemp_enter_network + unemp_educ)
local fam_educ=r(F)
local fam_educ_p=r(p)
test (grossunemp_enter_network + unemp_family)=(grossunemp_enter_network + unemp_coworker)
local fam_voc=r(F)
local fam_voc_p=r(p)
test (grossunemp_enter_network + unemp_educ)=(grossunemp_enter_network + unemp_coworker)
local educ_voc=r(F)
local educ_voc_p=r(p)

outreg2 using "$output\TableA9.xls", replace nocons nor ctitle("Guess national unemployment rate") bdec(3) sdec(3) adec(3) label keep(grossunemp_enter_network_share $link_vars) ///
adds(Outcome mean,`mean_outcome', Outcome sd,`sd_outcome', Unemployment shock mean,`mean_shock',  Unemployment shock sd,`sd_shock', Familial tie mean,`mean_fam', Educational tie mean,`mean_educ', Vocational tie mean,`mean_voc', F-test familial-educational,`fam_educ', F-test familial-vocational,`fam_voc',  F-test educational-vocational,`educ_voc', p-val familial-educational,`fam_educ_p', p-val familial-vocational,`fam_voc_p',  p-val educational-vocational,`educ_voc_p')

display c(current_time)









***************************************************** FORECAST OF NATIONAL UNEMPLOYMENT RATE ******************************************************

* Outcome only available in 2011

use "National Unemployment Forecast RF for Analysis - Last Year.dta", clear

* Merge in unemployment rate estimate errors from last year 
merge 1:1 year unique unique_network using "i-j link type dummy"
keep if _merge==3
drop _merge

bysort unique year: egen grossunemp_enter_network_share=mean(grossunemp_enter_network)
bysort unique year: egen dummy_family_share=mean(dummy_family)
bysort unique year: egen dummy_educ_share=mean(dummy_educ)
bysort unique year: egen dummy_coworker_share=mean(dummy_coworker)
drop *_network dummy_family dummy_educ dummy_coworker
duplicates drop unique year, force

* Interactions
g unemp_family=grossunemp_enter_network_share*dummy_family_share
g unemp_educ=grossunemp_enter_network_share*dummy_educ_share
g unemp_coworker=grossunemp_enter_network_share*dummy_coworker_share

tab year 

lab var grossunemp_enter_network_share "Unemployment shock (network share)"
lab var dummy_family_share "Familial link (i-j share)"
lab var dummy_educ_share "Educational link (i-j share)"
lab var dummy_coworker_share "Vocational link (i-j share)"
lab var unemp_family "Unemployment shock x Familial link"
lab var unemp_educ "Unemployment shock x Educational link"
lab var unemp_coworker "Unemployment shock x Vocational link"
global link_vars "dummy_family_share dummy_educ_share dummy_coworker_share unemp_family unemp_educ unemp_coworker"

replace unemp_rate_estimate_next=unemp_rate_estimate_next/100

* Results
display c(current_time)
reghdfe unemp_rate_estimate_next grossunemp_enter_network_share $link_vars, absorb(both ind2_year ocp_year educ_year) cluster(muni)
sum unemp_rate_estimate_next if e(sample)==1
local mean_outcome=r(mean)
local sd_outcome=r(sd)
sum grossunemp_enter_network_share if e(sample)==1
local mean_shock=r(mean)
local sd_shock=r(sd)
sum dummy_family_share if e(sample)==1
local mean_fam=r(mean)
sum dummy_educ_share if e(sample)==1
local mean_educ=r(mean)
sum dummy_coworker_share if e(sample)==1
local mean_voc=r(mean)

test (grossunemp_enter_network + unemp_family)=(grossunemp_enter_network + unemp_educ)
local fam_educ=r(F)
local fam_educ_p=r(p)
test (grossunemp_enter_network + unemp_family)=(grossunemp_enter_network + unemp_coworker)
local fam_voc=r(F)
local fam_voc_p=r(p)
test (grossunemp_enter_network + unemp_educ)=(grossunemp_enter_network + unemp_coworker)
local educ_voc=r(F)
local educ_voc_p=r(p)

outreg2 using "$output\TableA9.xls", append nocons nor ctitle("National unemployment rate expectation") bdec(3) sdec(3) adec(3) label keep(grossunemp_enter_network_share $link_vars) ///
adds(Outcome mean,`mean_outcome', Outcome sd,`sd_outcome', Unemployment shock mean,`mean_shock',  Unemployment shock sd,`sd_shock', Familial tie mean,`mean_fam', Educational tie mean,`mean_educ', Vocational tie mean,`mean_voc', F-test familial-educational,`fam_educ', F-test familial-vocational,`fam_voc',  F-test educational-vocational,`educ_voc', p-val familial-educational,`fam_educ_p', p-val familial-vocational,`fam_voc_p',  p-val educational-vocational,`educ_voc_p')

display c(current_time)






***************************************************** UNEMPLOYMENT OUTCOMES - PROBABILITY ******************************************************

use "Unemployment Outcomes RF for Analysis - Last Year.dta", clear

* Merge in unemployment rate estimate errors from last year 
merge 1:1 year unique unique_network using "i-j link type dummy"
keep if _merge==3
drop _merge

bysort unique year: egen grossunemp_enter_network_share=mean(grossunemp_enter_network)
bysort unique year: egen dummy_family_share=mean(dummy_family)
bysort unique year: egen dummy_educ_share=mean(dummy_educ)
bysort unique year: egen dummy_coworker_share=mean(dummy_coworker)
drop *_network dummy_family dummy_educ dummy_coworker
duplicates drop unique year, force

* Interactions
g unemp_family=grossunemp_enter_network_share*dummy_family_share
g unemp_educ=grossunemp_enter_network_share*dummy_educ_share
g unemp_coworker=grossunemp_enter_network_share*dummy_coworker_share

tab year 

lab var grossunemp_enter_network_share "Unemployment shock (network share)"
lab var dummy_family_share "Familial link (i-j share)"
lab var dummy_educ_share "Educational link (i-j share)"
lab var dummy_coworker_share "Vocational link (i-j share)"
lab var unemp_family "Unemployment shock x Familial link"
lab var unemp_educ "Unemployment shock x Educational link"
lab var unemp_coworker "Unemployment shock x Vocational link"
global link_vars "dummy_family_share dummy_educ_share dummy_coworker_share unemp_family unemp_educ unemp_coworker"

replace prob_unemployed=prob_unemployed/100

* Results
display c(current_time)
reghdfe prob_unemployed grossunemp_enter_network_share $link_vars, absorb(both ind2_year ocp_year educ_year) cluster(muni)
sum prob_unemployed if e(sample)==1
local mean_outcome=r(mean)
local sd_outcome=r(sd)
sum grossunemp_enter_network_share if e(sample)==1
local mean_shock=r(mean)
local sd_shock=r(sd)
sum dummy_family_share if e(sample)==1
local mean_fam=r(mean)
sum dummy_educ_share if e(sample)==1
local mean_educ=r(mean)
sum dummy_coworker_share if e(sample)==1
local mean_voc=r(mean)

test (grossunemp_enter_network + unemp_family)=(grossunemp_enter_network + unemp_educ)
local fam_educ=r(F)
local fam_educ_p=r(p)
test (grossunemp_enter_network + unemp_family)=(grossunemp_enter_network + unemp_coworker)
local fam_voc=r(F)
local fam_voc_p=r(p)
test (grossunemp_enter_network + unemp_educ)=(grossunemp_enter_network + unemp_coworker)
local educ_voc=r(F)
local educ_voc_p=r(p)

outreg2 using "$output\TableA9.xls", append nocons nor ctitle("Own unemployment expectation") bdec(3) sdec(3) adec(3) label keep(grossunemp_enter_network_share $link_vars) ///
adds(Outcome mean,`mean_outcome', Outcome sd,`sd_outcome', Unemployment shock mean,`mean_shock',  Unemployment shock sd,`sd_shock', Familial tie mean,`mean_fam', Educational tie mean,`mean_educ', Vocational tie mean,`mean_voc', F-test familial-educational,`fam_educ', F-test familial-vocational,`fam_voc',  F-test educational-vocational,`educ_voc', p-val familial-educational,`fam_educ_p', p-val familial-vocational,`fam_voc_p',  p-val educational-vocational,`educ_voc_p')

display c(current_time)







***************************************************** UNEMPLOYMENT OUTCOMES - UI POLICY ******************************************************

use "UI Outcomes RF for Analysis - Last Year.dta", clear

* Merge in unemployment rate estimate errors from last year 
merge 1:1 year unique unique_network using "i-j link type dummy"
keep if _merge==3
drop _merge

bysort unique year: egen grossunemp_enter_network_share=mean(grossunemp_enter_network)
bysort unique year: egen dummy_family_share=mean(dummy_family)
bysort unique year: egen dummy_educ_share=mean(dummy_educ)
bysort unique year: egen dummy_coworker_share=mean(dummy_coworker)
drop *_network dummy_family dummy_educ dummy_coworker
duplicates drop unique year, force

* Interactions
g unemp_family=grossunemp_enter_network_share*dummy_family_share
g unemp_educ=grossunemp_enter_network_share*dummy_educ_share
g unemp_coworker=grossunemp_enter_network_share*dummy_coworker_share

tab year 

lab var grossunemp_enter_network_share "Unemployment shock (network share)"
lab var dummy_family_share "Familial link (i-j share)"
lab var dummy_educ_share "Educational link (i-j share)"
lab var dummy_coworker_share "Vocational link (i-j share)"
lab var unemp_family "Unemployment shock x Familial link"
lab var unemp_educ "Unemployment shock x Educational link"
lab var unemp_coworker "Unemployment shock x Vocational link"
global link_vars "dummy_family_share dummy_educ_share dummy_coworker_share unemp_family unemp_educ unemp_coworker"

* Results
display c(current_time)
reghdfe more_ui grossunemp_enter_network_share $link_vars, absorb(both ind2_year ocp_year educ_year) cluster(muni)
sum more_ui if e(sample)==1
local mean_outcome=r(mean)
local sd_outcome=r(sd)
sum grossunemp_enter_network_share if e(sample)==1
local mean_shock=r(mean)
local sd_shock=r(sd)
sum dummy_family_share if e(sample)==1
local mean_fam=r(mean)
sum dummy_educ_share if e(sample)==1
local mean_educ=r(mean)
sum dummy_coworker_share if e(sample)==1
local mean_voc=r(mean)

test (grossunemp_enter_network + unemp_family)=(grossunemp_enter_network + unemp_educ)
local fam_educ=r(F)
local fam_educ_p=r(p)
test (grossunemp_enter_network + unemp_family)=(grossunemp_enter_network + unemp_coworker)
local fam_voc=r(F)
local fam_voc_p=r(p)
test (grossunemp_enter_network + unemp_educ)=(grossunemp_enter_network + unemp_coworker)
local educ_voc=r(F)
local educ_voc_p=r(p)

outreg2 using "$output\TableA9.xls", append nocons nor ctitle("Want more unemployment insurance") bdec(3) sdec(3) adec(3) label keep(grossunemp_enter_network_share $link_vars) ///
adds(Outcome mean,`mean_outcome', Outcome sd,`sd_outcome', Unemployment shock mean,`mean_shock',  Unemployment shock sd,`sd_shock', Familial tie mean,`mean_fam', Educational tie mean,`mean_educ', Vocational tie mean,`mean_voc', F-test familial-educational,`fam_educ', F-test familial-vocational,`fam_voc',  F-test educational-vocational,`educ_voc', p-val familial-educational,`fam_educ_p', p-val familial-vocational,`fam_voc_p',  p-val educational-vocational,`educ_voc_p')

display c(current_time)








***************************************************** IDEOLOGY OUTCOMES ******************************************************

use "Ideology RF for Analysis - Last Year.dta", clear

* Merge in unemployment rate estimate errors from last year 
merge 1:1 year unique unique_network using "i-j link type dummy"
keep if _merge==3
drop _merge

bysort unique year: egen grossunemp_enter_network_share=mean(grossunemp_enter_network)
bysort unique year: egen dummy_family_share=mean(dummy_family)
bysort unique year: egen dummy_educ_share=mean(dummy_educ)
bysort unique year: egen dummy_coworker_share=mean(dummy_coworker)
drop *_network dummy_family dummy_educ dummy_coworker
duplicates drop unique year, force

* Interactions
g unemp_family=grossunemp_enter_network_share*dummy_family_share
g unemp_educ=grossunemp_enter_network_share*dummy_educ_share
g unemp_coworker=grossunemp_enter_network_share*dummy_coworker_share

tab year 

lab var grossunemp_enter_network_share "Unemployment shock (network share)"
lab var dummy_family_share "Familial link (i-j share)"
lab var dummy_educ_share "Educational link (i-j share)"
lab var dummy_coworker_share "Vocational link (i-j share)"
lab var unemp_family "Unemployment shock x Familial link"
lab var unemp_educ "Unemployment shock x Educational link"
lab var unemp_coworker "Unemployment shock x Vocational link"
global link_vars "dummy_family_share dummy_educ_share dummy_coworker_share unemp_family unemp_educ unemp_coworker"

* Results
display c(current_time)
reghdfe govt_more_help grossunemp_enter_network_share $link_vars, absorb(both ind2_year ocp_year educ_year) cluster(muni)
sum govt_more_help if e(sample)==1
local mean_outcome=r(mean)
local sd_outcome=r(sd)
sum grossunemp_enter_network_share if e(sample)==1
local mean_shock=r(mean)
local sd_shock=r(sd)
sum dummy_family_share if e(sample)==1
local mean_fam=r(mean)
sum dummy_educ_share if e(sample)==1
local mean_educ=r(mean)
sum dummy_coworker_share if e(sample)==1
local mean_voc=r(mean)

test (grossunemp_enter_network + unemp_family)=(grossunemp_enter_network + unemp_educ)
local fam_educ=r(F)
local fam_educ_p=r(p)
test (grossunemp_enter_network + unemp_family)=(grossunemp_enter_network + unemp_coworker)
local fam_voc=r(F)
local fam_voc_p=r(p)
test (grossunemp_enter_network + unemp_educ)=(grossunemp_enter_network + unemp_coworker)
local educ_voc=r(F)
local educ_voc_p=r(p)

outreg2 using "$output\TableA9.xls", append nocons nor ctitle("Government should support the poor") bdec(3) sdec(3) adec(3) label keep(grossunemp_enter_network_share $link_vars) ///
adds(Outcome mean,`mean_outcome', Outcome sd,`sd_outcome', Unemployment shock mean,`mean_shock',  Unemployment shock sd,`sd_shock', Familial tie mean,`mean_fam', Educational tie mean,`mean_educ', Vocational tie mean,`mean_voc', F-test familial-educational,`fam_educ', F-test familial-vocational,`fam_voc',  F-test educational-vocational,`educ_voc', p-val familial-educational,`fam_educ_p', p-val familial-vocational,`fam_voc_p',  p-val educational-vocational,`educ_voc_p')

display c(current_time)











***************************************************** ECONOMIC POLICY ******************************************************

* These questions were not asked in 2012

use "Economic Policy Outcomes RF for Analysis - Last Year.dta", clear

* Merge in unemployment rate estimate errors from last year 
merge 1:1 year unique unique_network using "i-j link type dummy"
keep if _merge==3
drop _merge

bysort unique year: egen grossunemp_enter_network_share=mean(grossunemp_enter_network)
bysort unique year: egen dummy_family_share=mean(dummy_family)
bysort unique year: egen dummy_educ_share=mean(dummy_educ)
bysort unique year: egen dummy_coworker_share=mean(dummy_coworker)
drop *_network dummy_family dummy_educ dummy_coworker
duplicates drop unique year, force

* Interactions
g unemp_family=grossunemp_enter_network_share*dummy_family_share
g unemp_educ=grossunemp_enter_network_share*dummy_educ_share
g unemp_coworker=grossunemp_enter_network_share*dummy_coworker_share

tab year 

lab var grossunemp_enter_network_share "Unemployment shock (network share)"
lab var dummy_family_share "Familial link (i-j share)"
lab var dummy_educ_share "Educational link (i-j share)"
lab var dummy_coworker_share "Vocational link (i-j share)"
lab var unemp_family "Unemployment shock x Familial link"
lab var unemp_educ "Unemployment shock x Educational link"
lab var unemp_coworker "Unemployment shock x Vocational link"
global link_vars "dummy_family_share dummy_educ_share dummy_coworker_share unemp_family unemp_educ unemp_coworker"

* Results
display c(current_time)
reghdfe gov_solution grossunemp_enter_network_share $link_vars, absorb(both ind2_year ocp_year educ_year) cluster(muni)
sum gov_solution if e(sample)==1
local mean_outcome=r(mean)
local sd_outcome=r(sd)
sum grossunemp_enter_network_share if e(sample)==1
local mean_shock=r(mean)
local sd_shock=r(sd)
sum dummy_family_share if e(sample)==1
local mean_fam=r(mean)
sum dummy_educ_share if e(sample)==1
local mean_educ=r(mean)
sum dummy_coworker_share if e(sample)==1
local mean_voc=r(mean)

test (grossunemp_enter_network + unemp_family)=(grossunemp_enter_network + unemp_educ)
local fam_educ=r(F)
local fam_educ_p=r(p)
test (grossunemp_enter_network + unemp_family)=(grossunemp_enter_network + unemp_coworker)
local fam_voc=r(F)
local fam_voc_p=r(p)
test (grossunemp_enter_network + unemp_educ)=(grossunemp_enter_network + unemp_coworker)
local educ_voc=r(F)
local educ_voc_p=r(p)

outreg2 using "$output\TableA9.xls", append nocons nor ctitle("Support non-market-based stimulus") bdec(3) sdec(3) adec(3) label keep(grossunemp_enter_network_share $link_vars) ///
adds(Outcome mean,`mean_outcome', Outcome sd,`sd_outcome', Unemployment shock mean,`mean_shock',  Unemployment shock sd,`sd_shock', Familial tie mean,`mean_fam', Educational tie mean,`mean_educ', Vocational tie mean,`mean_voc', F-test familial-educational,`fam_educ', F-test familial-vocational,`fam_voc',  F-test educational-vocational,`educ_voc', p-val familial-educational,`fam_educ_p', p-val familial-vocational,`fam_voc_p',  p-val educational-vocational,`educ_voc_p')

display c(current_time)








***************************************************** VOTING LEFT (INTENTION) ******************************************************

use "Voting RF for Analysis - Last Year.dta", clear

* Merge in unemployment rate estimate errors from last year 
merge 1:1 year unique unique_network using "i-j link type dummy"
keep if _merge==3
drop _merge

bysort unique year: egen grossunemp_enter_network_share=mean(grossunemp_enter_network)
bysort unique year: egen dummy_family_share=mean(dummy_family)
bysort unique year: egen dummy_educ_share=mean(dummy_educ)
bysort unique year: egen dummy_coworker_share=mean(dummy_coworker)
drop *_network dummy_family dummy_educ dummy_coworker
duplicates drop unique year, force

* Interactions
g unemp_family=grossunemp_enter_network_share*dummy_family_share
g unemp_educ=grossunemp_enter_network_share*dummy_educ_share
g unemp_coworker=grossunemp_enter_network_share*dummy_coworker_share

tab year 

lab var grossunemp_enter_network_share "Unemployment shock (network share)"
lab var dummy_family_share "Familial link (i-j share)"
lab var dummy_educ_share "Educational link (i-j share)"
lab var dummy_coworker_share "Vocational link (i-j share)"
lab var unemp_family "Unemployment shock x Familial link"
lab var unemp_educ "Unemployment shock x Educational link"
lab var unemp_coworker "Unemployment shock x Vocational link"
global link_vars "dummy_family_share dummy_educ_share dummy_coworker_share unemp_family unemp_educ unemp_coworker"

* Results
display c(current_time)
reghdfe vote_left grossunemp_enter_network_share $link_vars, absorb(both ind2_year ocp_year educ_year) cluster(muni)
sum vote_left if e(sample)==1
local mean_outcome=r(mean)
local sd_outcome=r(sd)
sum grossunemp_enter_network_share if e(sample)==1
local mean_shock=r(mean)
local sd_shock=r(sd)
sum dummy_family_share if e(sample)==1
local mean_fam=r(mean)
sum dummy_educ_share if e(sample)==1
local mean_educ=r(mean)
sum dummy_coworker_share if e(sample)==1
local mean_voc=r(mean)

test (grossunemp_enter_network + unemp_family)=(grossunemp_enter_network + unemp_educ)
local fam_educ=r(F)
local fam_educ_p=r(p)
test (grossunemp_enter_network + unemp_family)=(grossunemp_enter_network + unemp_coworker)
local fam_voc=r(F)
local fam_voc_p=r(p)
test (grossunemp_enter_network + unemp_educ)=(grossunemp_enter_network + unemp_coworker)
local educ_voc=r(F)
local educ_voc_p=r(p)

outreg2 using "$output\TableA9.xls", append nocons nor ctitle("Intend to vote for left party") bdec(3) sdec(3) adec(3) label keep(grossunemp_enter_network_share $link_vars) ///
adds(Outcome mean,`mean_outcome', Outcome sd,`sd_outcome', Unemployment shock mean,`mean_shock',  Unemployment shock sd,`sd_shock', Familial tie mean,`mean_fam', Educational tie mean,`mean_educ', Vocational tie mean,`mean_voc', F-test familial-educational,`fam_educ', F-test familial-vocational,`fam_voc',  F-test educational-vocational,`educ_voc', p-val familial-educational,`fam_educ_p', p-val familial-vocational,`fam_voc_p',  p-val educational-vocational,`educ_voc_p')

display c(current_time)











***************************************************** VOTED LEFT ******************************************************

* These questions were only asked in 2011 - ie the year before which the shocks definitely occurred before the election

use "Voted RF for Analysis - Last Year.dta", clear

* Merge in unemployment rate estimate errors from last year 
merge 1:1 year unique unique_network using "i-j link type dummy"
keep if _merge==3
drop _merge

bysort unique year: egen grossunemp_enter_network_share=mean(grossunemp_enter_network)
bysort unique year: egen dummy_family_share=mean(dummy_family)
bysort unique year: egen dummy_educ_share=mean(dummy_educ)
bysort unique year: egen dummy_coworker_share=mean(dummy_coworker)
drop *_network dummy_family dummy_educ dummy_coworker
duplicates drop unique year, force

* Interactions
g unemp_family=grossunemp_enter_network_share*dummy_family_share
g unemp_educ=grossunemp_enter_network_share*dummy_educ_share
g unemp_coworker=grossunemp_enter_network_share*dummy_coworker_share

tab year 

lab var grossunemp_enter_network_share "Unemployment shock (network share)"
lab var dummy_family_share "Familial link (i-j share)"
lab var dummy_educ_share "Educational link (i-j share)"
lab var dummy_coworker_share "Vocational link (i-j share)"
lab var unemp_family "Unemployment shock x Familial link"
lab var unemp_educ "Unemployment shock x Educational link"
lab var unemp_coworker "Unemployment shock x Vocational link"
global link_vars "dummy_family_share dummy_educ_share dummy_coworker_share unemp_family unemp_educ unemp_coworker"

* Results
display c(current_time)
reghdfe voted_left_2011 grossunemp_enter_network_share $link_vars, absorb(both ind2_year ocp_year educ_year) cluster(muni)
sum voted_left_2011 if e(sample)==1
local mean_outcome=r(mean)
local sd_outcome=r(sd)
sum grossunemp_enter_network_share if e(sample)==1
local mean_shock=r(mean)
local sd_shock=r(sd)
sum dummy_family_share if e(sample)==1
local mean_fam=r(mean)
sum dummy_educ_share if e(sample)==1
local mean_educ=r(mean)
sum dummy_coworker_share if e(sample)==1
local mean_voc=r(mean)

test (grossunemp_enter_network + unemp_family)=(grossunemp_enter_network + unemp_educ)
local fam_educ=r(F)
local fam_educ_p=r(p)
test (grossunemp_enter_network + unemp_family)=(grossunemp_enter_network + unemp_coworker)
local fam_voc=r(F)
local fam_voc_p=r(p)
test (grossunemp_enter_network + unemp_educ)=(grossunemp_enter_network + unemp_coworker)
local educ_voc=r(F)
local educ_voc_p=r(p)

outreg2 using "$output\TableA9.xls", append nocons nor ctitle("Voted for left party in 2001") bdec(3) sdec(3) adec(3) label keep(grossunemp_enter_network_share $link_vars) ///
adds(Outcome mean,`mean_outcome', Outcome sd,`sd_outcome', Unemployment shock mean,`mean_shock',  Unemployment shock sd,`sd_shock', Familial tie mean,`mean_fam', Educational tie mean,`mean_educ', Vocational tie mean,`mean_voc', F-test familial-educational,`fam_educ', F-test familial-vocational,`fam_voc',  F-test educational-vocational,`educ_voc', p-val familial-educational,`fam_educ_p', p-val familial-vocational,`fam_voc_p',  p-val educational-vocational,`educ_voc_p')

display c(current_time)









































